package cn.chenmixuexi.spring;

import cn.chenmixuexi.proxy.RpcProxy;
import cn.chenmixuexi.server.service.HelloService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.PropertyValues;
import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor;
import org.springframework.stereotype.Component;
@Slf4j
//@Component
public class BeanPostProcessor implements InstantiationAwareBeanPostProcessor {
//    @Override
//    public Object postProcessBeforeInitialization(Class<?> beanClass, String beanName) throws BeansException {
//        if(beanClass.isInterface()){
//            System.out.println("helloService");
//            return RpcProxy.getProxyService(beanClass);
//        }
//        return InstantiationAwareBeanPostProcessor.super.postProcessBeforeInitialization(beanClass, beanName);
//    }


//    public  Object postProcessBeforeInstantiation

    @Override
    public Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) throws BeansException {
        System.out.println(beanClass.toString());
        if(beanClass.isInterface()){
            System.out.println("helloService");
            return RpcProxy.getProxyService(beanClass);
        }
        return InstantiationAwareBeanPostProcessor.super.postProcessBeforeInstantiation(beanClass, beanName);
    }

//    @Override
//    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
//        if(bean instanceof ){
//            System.out.println("helloService");
//            return RpcProxy.getProxyService(beanClass);
//        }
//        return InstantiationAwareBeanPostProcessor.super.postProcessBeforeInitialization(bean, beanName);
//    }
}
